312A - Whose sentence is it - CodeForces Solution


implementation strings *1100

Please click on ads to support us..

Python Code:

def whose_message(a):
    if a[:5]=='miao.' and a[-5:]!='lala.':
        return "Rainbow's"
    if a[:5] != 'miao.' and a[-5:] == 'lala.':
        return "Freda's"
    return "OMG>.< I don't know!"
t=int(input())
for i in range(t):
    m=input()
    print(whose_message(m))

C++ Code:

#include<bits/stdc++.h> 
using namespace std; 

string whoSaidIt(string s) {
    bool freda = false; 
    bool rainbow = false; 
    string itFreda = "Freda's", itRainbow = "Rainbow's", donnu = "OMG>.< I don't know!"; 
    string lala = "lala." , meow = "miao.";
    int index = 0, n = (int) s.size(); 
    while (index < min(5, (int)s.size())) {
        if (meow[index] != s[index])
           break;
        index ++; 
    }
    if (index == 5)
        rainbow = true; 
    index = 0; 
    while (index < 5 && n - 5 + index >= 0) {
        if (lala[index] != s[n - 5 + index])
           break;
        index ++; 
    }
    if (index == 5)
       freda = true; 
    if (freda == rainbow) 
       return donnu;
    if (freda)
        return itFreda;
    if (rainbow) 
       return itRainbow; 
}
int main() {
   int n; 
   string s; 
   cin >> n; 
   getline(cin, s); 
   while(n--) {
       getline(cin, s); 
       cout << whoSaidIt(s) << endl; 
   }
}


Comments

Submit
0 Comments
More Questions

34. Find First and Last Position of Element in Sorted Array
33. Search in Rotated Sorted Array
17. Letter Combinations of a Phone Number
5. Longest Palindromic Substring
3. Longest Substring Without Repeating Characters
1312. Minimum Insertion Steps to Make a String Palindrome
1092. Shortest Common Supersequence
1044. Longest Duplicate Substring
1032. Stream of Characters
987. Vertical Order Traversal of a Binary Tree
952. Largest Component Size by Common Factor
212. Word Search II
174. Dungeon Game
127. Word Ladder
123. Best Time to Buy and Sell Stock III
85. Maximal Rectangle
84. Largest Rectangle in Histogram
60. Permutation Sequence
42. Trapping Rain Water
32. Longest Valid Parentheses
Cutting a material
Bubble Sort
Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph